package com.zbkj.admin.controller.merchant;

import com.github.pagehelper.PageInfo;
import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.activity.SportfolioMarketActivity;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.merchant.MerchantSportfolioMarketSearchRequest;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.MerchantSportfolioMarketActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Objects;


/**
 * 组合营销满赠管理 前端控制器
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/merchant/sportfolioMarket")
@Api(tags = "商户组合营销满赠满赠管理控制器")
public class MerchantSportfolioMarketActivityController {

    @Autowired
    private MerchantSportfolioMarketActivityService sportfolioMarketActivityService;

    @PreAuthorize("hasAuthority('merchant:sportfolioMarket:list')")
    @ApiOperation(value = "商户组合营销满赠分页列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<PageInfo<SportfolioMarketActivity>> getList(@Validated MerchantSportfolioMarketSearchRequest request,
                                                                 @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(sportfolioMarketActivityService.findPage(request, pageParamRequest));
    }

    @PreAuthorize("hasAuthority('merchant:sportfolioMarket:detail')")
    @ApiOperation(value = "商户组合营销满赠详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public CommonResult<SportfolioMarketActivity> activityDetail(@PathVariable("id") Integer id) {
        return CommonResult.success(sportfolioMarketActivityService.activityDetail(id));
    }

    @PreAuthorize("hasAuthority('merchant:sportfolioMarket:add')")
//    @LogControllerAnnotation(intoDB = true, methodType = MethodType.ADD, description = "新增商户组合营销满赠")
    @ApiOperation(value = "新增商户组合营销满赠")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<Object> save(@RequestBody SportfolioMarketActivity activity) {
        if (sportfolioMarketActivityService.add(activity)) {
            return CommonResult.success().setMessage("新增商户组合营销满赠成功");

        }
        return CommonResult.failed().setMessage("新增商户组合营销满赠失败");
    }

    @PreAuthorize("hasAuthority('merchant:sportfolioMarket:update')")
//    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "修改商户组合营销满赠")
    @ApiOperation(value = "修改商户组合营销满赠")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<Object> update(@RequestBody SportfolioMarketActivity activity) {
        if (sportfolioMarketActivityService.updateSportfolioMarket(activity)) {
            return CommonResult.success().setMessage("修改商户组合营销满赠成功");
        }
        return CommonResult.failed().setMessage("修改商户组合营销满赠失败");
    }

    @PreAuthorize("hasAuthority('merchant:SportfolioMarket:delete')")
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "删除商户组合营销满赠")
    @ApiOperation(value = "删除商户组合营销满赠")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public CommonResult<Object> delete(@PathVariable(value = "id") Integer id) {
        if (sportfolioMarketActivityService.delete(id)) {
            return CommonResult.success().setMessage("删除商户组合营销满赠成功");
        }
        return CommonResult.failed().setMessage("删除商户组合营销满赠失败");
    }
}



